from scrapy.spider import BaseSpider
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
from listaurl.items import ListaurlItem

class OldSpider(CrawlSpider):
    name = 'oldurl'
    allowed_domains = ['www.thereminvox.com']
    start_urls = ['http://www.thereminvox.com']

    rules = (
        # Extract links matching 'category.php' (but not matching 'subsection.php')
        # and follow links from them (since no callback means follow=True by default).
        #Rule(SgmlLinkExtractor(allow=('index\.html',)),  callback='parse_item'),
        #Rule(SgmlLinkExtractor(deny=('.*gotolink.*',)),  ),
        Rule(SgmlLinkExtractor(allow_domains=('www.thereminvox.com',)),  callback='parse_item', follow=True ),

        # Extract links matching 'item.php' and parse them with the spider's method parse_item
        #Rule(SgmlLinkExtractor(allow=('item\.php', )), callback='parse_item'),
    )

    def parse_item(self, response):
        #self.log('Hi, this is an item page! %s' % response.url)

        sel = Selector(response)
        item = ListaurlItem()
        item['tvoxurl'] = response.url
        #item['name'] = sel.xpath('//td[@id="item_name"]/text()').extract()
        #item['description'] = sel.xpath('//td[@id="item_description"]/text()').extract()
        return item






